package com.buba.system.dao.impl;

import com.buba.system.dao.LoginDao;
import com.buba.system.pojo.UserInfo;
import com.buba.util.DBPool;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;
import java.util.Map;

public class LoginDaoImpl implements LoginDao {
    //dbutils提供的数据库操作类，将连接池的数据源传递给QueryRunner
    QueryRunner queryRunner = new QueryRunner(DBPool.getDS());
    @Override
    public UserInfo login(Map<String, String> param) {
        String sql = "select * from userinfo where UserName=? and PassWord=?";
        try {
            UserInfo query = queryRunner.query(sql,new BeanHandler<UserInfo>(UserInfo.class),param.get("account"),param.get("password"));
            return query;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
